package dbexp.model.db;

import java.io.Serializable;
import java.util.Vector;

import dbexp.model.DbObject;
import dbexp.model.User;

/**
 * @author Michał Skrzyński
 * @email michal_skrzynski@o2.pl
 */
public class DbUser extends User implements Serializable {
	private static final long serialVersionUID = 1L;
	private String connectionName = "polaczenie1";
	private String schemaName = null;
	private String pass = null;
	private String hostName = null;
	private int portNumber = -1;
	private String dbName = null;
	private transient Vector<DbObject> objectPrivs = new Vector<DbObject>();

	public DbUser() {

	}

	public DbUser(String dbName, String hostName, String pass, int portNumber,
			String schemaName) {
		this.dbName = dbName;
		this.hostName = hostName;
		this.pass = pass;
		this.portNumber = portNumber;
		this.schemaName = schemaName;
	}

	public String getSchemaName() {
		return (schemaName != null) ? schemaName : null;
	}

	public String getPass() {
		return pass;
	}

	public String getHostName() {
		return hostName;
	}

	public int getPortNumber() {
		return portNumber;
	}

	public String getDbName() {
		return dbName;
	}

	public String getConnectionName() {
		return connectionName;
	}

	public void setConnectionName(String connectionName) {
		this.connectionName = connectionName;
	}

	public Vector<DbObject> getObjectPrivs() {
		return objectPrivs;
	}

	public void setObjectPrivs(Vector<DbObject> objectPrivs) {
		this.objectPrivs = objectPrivs;
	}

	public boolean isRole(String rola) {
		return role.contains(rola);
	}

	public void addObjectPrivs(DbObject ob) {
		objectPrivs.add(ob);
	}

	public boolean isObjectPrivs(DbObject ob) {
		return objectPrivs.contains(ob);
	}

	public boolean isAccessToDBA() {// EXP_FULL_DATABASE
		return ((role.contains("DBA"))
				|| (role.contains("SELECT_CATALOG_ROLE"))
				|| (role.contains("EXP_FULL_DATABASE"))
				|| (role.contains("IMP_FULL_DATABASE"))
				|| (role.contains("EXECUTE_CATALOG_ROLE"))
				|| (role.contains("HS_ADMIN_ROLE"))
				|| (role.contains("AQ_USER_ROLE"))
				|| (role.contains("AQ_ADMINISTRATOR_ROLE"))
				|| (role.contains("EXECUTE_CATALOG_ROLE")) || (systemPrivs
				.contains("SELECT ANY DICTIONARY")));
	}
}
